<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
        const str = 'ab cdef';

        //遍历字符串方式一
        /*    for(let item of str){
               console.log(item)
           } */


        //方式二
        const iteratorStr = str[Symbol.iterator]()
        /*         let item = iteratorStr.next();
                console.log(item.value)
                console.log(item.done)  //是否遍历到末尾
         */

        //  const array1 = [];
        //输出ab
       /*  let theChar = iteratorStr.next()
        while (!theChar.done && theChar.value !== ' ') {
            array1.push(theChar.value)
            console.log(theChar.value)
            theChar = iteratorStr.next()
        }
 */
        //需求：将字符串转换为数组
        const array1 = Array.from(str);
        console.log(array1)



    </script>
</head>

<body>

</body>

</html>